package com.cloud.adrian.novel.config;

import com.cloud.adrian.novel.common.constant.AmqpConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitMQ 配置
 * @Author: xiangguiliang
 * @version: 1.0
 * @since: 2024/05/15
 */
@Configuration
public class AmqpConfig {
    /**
     * 小说信息改变交换机
     */
    @Bean
    public TopicExchange novelExchange() {
        return new TopicExchange(AmqpConstants.BookChange.EXCHANGE_NAME, true, false);
    }

    /**
     * 小说新增队列
     */
    @Bean
    public Queue insertQueue() {
        return new Queue(AmqpConstants.BookChange.INSERT_QUEUE, true);
    }

    /**
     * 小说更新队列
     */
    @Bean
    public Queue updateQueue() {
        return new Queue(AmqpConstants.BookChange.UPDATE_QUEUE, true);
    }

    /**
     * 小说删除队列
     */
    @Bean
    public Queue deleteQueue() {
        return new Queue(AmqpConstants.BookChange.DELETE_QUEUE, true);
    }

    /**
     * 新增队列绑定到交换机
     */
    @Bean
    public Binding insertBinding() {
        return BindingBuilder.bind(insertQueue()).to(novelExchange()).with(AmqpConstants.BookChange.INSERT_KEY);
    }

    /**
     * 更新队列绑定到交换机
     */
    @Bean
    public Binding updateBinding() {
        return BindingBuilder.bind(updateQueue()).to(novelExchange()).with(AmqpConstants.BookChange.UPDATE_KEY);
    }

    /**
     * 删除队列绑定到交换机
     */
    @Bean
    public Binding deleteBinding() {
        return BindingBuilder.bind(deleteQueue()).to(novelExchange()).with(AmqpConstants.BookChange.DELETE_KEY);
    }

}
